

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/maple_leaf.png">
  <link rel="icon" href="/blog/img/maple_leaf.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="枫🍁川">
  <meta name="keywords" content="">
  
    <meta name="description" content="我分了javascript和typescript两个版本的axios,虽然两份的逻辑都是一样的，但是写法上会有不同的方式  安装 axiosnpm install axios element-plus  这里我用了ElementPlus的轻量弹窗，安装成功后就可以在项目中使用了，具体使用方法可以查看 github，然后先在 src 目录下创建一个 utils 目录，再创建一个 https.js">
<meta property="og:type" content="article">
<meta property="og:title" content="二次封装 Axios (javascript)">
<meta property="og:url" content="https://destiny-yyc.github.io/second-axios.html">
<meta property="og:site_name" content="枫🍁川的博客">
<meta property="og:description" content="我分了javascript和typescript两个版本的axios,虽然两份的逻辑都是一样的，但是写法上会有不同的方式  安装 axiosnpm install axios element-plus  这里我用了ElementPlus的轻量弹窗，安装成功后就可以在项目中使用了，具体使用方法可以查看 github，然后先在 src 目录下创建一个 utils 目录，再创建一个 https.js">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-02-11T16:00:00.000Z">
<meta property="article:modified_time" content="2023-03-22T10:16:55.347Z">
<meta property="article:author" content="枫🍁川">
<meta property="article:tag" content="axios">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>二次封装 Axios (javascript) - 枫🍁川的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"destiny-yyc.github.io","root":"/blog/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/blog/js/utils.js" ></script>
  <script  src="/blog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/blog/">
      <strong>枫🍁川的博客</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/blog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="二次封装 Axios (javascript)"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        枫🍁川
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-02-12 00:00" pubdate>
          2022年2月12日
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          3.8k 字
        
      </span>
    

    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">二次封装 Axios (javascript)</h1>
            
            
              <div class="markdown-body">
                
                <blockquote>
<p>我分了<code>javascript</code>和<code>typescript</code>两个版本的axios,虽然两份的逻辑都是一样的，但是写法上会有不同的方式</p>
</blockquote>
<h3 id="安装-axios"><a href="#安装-axios" class="headerlink" title="安装 axios"></a><strong>安装 axios</strong></h3><div class="code-wrapper"><pre><code class="hljs bash">npm install axios element-plus</code></pre></div>

<p>这里我用了ElementPlus的轻量弹窗，安装成功后就可以在项目中使用了，<a target="_blank" rel="noopener" href="https://github.com/axios/axios">具体使用方法可以查看 github</a>，然后先在 src 目录下创建一个 utils 目录，再创建一个 https.js 文件，里面的编写如下：</p>
<h3 id="javascript的写法：直接在响应拦截里把处理逻辑"><a href="#javascript的写法：直接在响应拦截里把处理逻辑" class="headerlink" title="javascript的写法：直接在响应拦截里把处理逻辑"></a>javascript的写法：直接在响应拦截里把处理逻辑</h3><div class="code-wrapper"><pre><code class="hljs javascript"><span class="hljs-comment">//引入 axios</span>
<span class="hljs-keyword">import</span> axios <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;axios&quot;</span>;
<span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">ElMessage</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;element-plus&#x27;</span>;

<span class="hljs-keyword">const</span> request = axios.<span class="hljs-title function_">create</span>(&#123;
  <span class="hljs-attr">baseURL</span>: <span class="hljs-string">&#x27;/api&#x27;</span>,
  <span class="hljs-attr">timeout</span>: <span class="hljs-number">5000</span>
&#125;)

<span class="hljs-comment">// 数据请求拦截</span>
request.<span class="hljs-property">interceptors</span>.<span class="hljs-property">request</span>.<span class="hljs-title function_">use</span>(<span class="hljs-function">(<span class="hljs-params">config</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">return</span> config;
&#125;, <span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(error);
&#125;);

<span class="hljs-comment">// 返回响应数据拦截</span>
request.<span class="hljs-property">interceptors</span>.<span class="hljs-property">response</span>.<span class="hljs-title function_">use</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">const</span> data = res.<span class="hljs-property">data</span>;
  <span class="hljs-comment">// 状态码为 2xx 范围时都会调用该函数，处理响应数据</span>
  <span class="hljs-keyword">if</span> (res.<span class="hljs-property">status</span> === <span class="hljs-number">200</span>) &#123;
    <span class="hljs-keyword">const</span> code = data.<span class="hljs-property">code</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">resolve</span>(data);
  &#125;
&#125;, <span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">if</span> (error.<span class="hljs-property">response</span>.<span class="hljs-property">status</span>) &#123;
    <span class="hljs-comment">// 状态码超过 2xx 范围时都会调用该函数，处理错误响应</span>
    <span class="hljs-keyword">switch</span> (error.<span class="hljs-property">response</span>.<span class="hljs-property">status</span>) &#123;
      <span class="hljs-keyword">case</span> <span class="hljs-number">404</span>:
        <span class="hljs-title class_">ElMessage</span>(&#123;
          <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;error&#x27;</span>,
          <span class="hljs-attr">message</span>: <span class="hljs-string">&#x27;请求路径找不到！&#x27;</span>,
          <span class="hljs-attr">showClose</span>: <span class="hljs-literal">true</span>
        &#125;);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-number">502</span>:
        <span class="hljs-title class_">ElMessage</span>(&#123;
          <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;error&#x27;</span>,
          <span class="hljs-attr">message</span>: <span class="hljs-string">&#x27;服务器内部报错！&#x27;</span>,
          <span class="hljs-attr">showClose</span>: <span class="hljs-literal">true</span>
        &#125;);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-attr">default</span>:
        <span class="hljs-keyword">break</span>;
    &#125;
  &#125;
  <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(error);
&#125;);
<span class="hljs-keyword">export</span> &#123; request &#125;;</code></pre></div>

<h3 id="typescript的写法：新增了类型声明"><a href="#typescript的写法：新增了类型声明" class="headerlink" title="typescript的写法：新增了类型声明"></a>typescript的写法：新增了类型声明</h3><div class="code-wrapper"><pre><code class="hljs typescript"><span class="hljs-keyword">import</span> <span class="hljs-keyword">type</span> &#123; <span class="hljs-title class_">AxiosResponse</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;axios&quot;</span>;
<span class="hljs-keyword">import</span> axios <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;axios&quot;</span>;
<span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">ElMessage</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;element-plus&quot;</span>;

<span class="hljs-comment">// 请求拦截</span>
axios.<span class="hljs-property">interceptors</span>.<span class="hljs-property">request</span>.<span class="hljs-title function_">use</span>(<span class="hljs-function">(<span class="hljs-params">config: <span class="hljs-built_in">any</span></span>) =&gt;</span> &#123;
	<span class="hljs-comment">// 可在此处添加token等信息</span>
  <span class="hljs-keyword">return</span> config
&#125;, <span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">return</span> error
&#125;)

<span class="hljs-comment">// 响应拦截</span>
axios.<span class="hljs-property">interceptors</span>.<span class="hljs-property">response</span>.<span class="hljs-title function_">use</span>(<span class="hljs-function">(<span class="hljs-params">config: <span class="hljs-built_in">any</span></span>) =&gt;</span> &#123;
	 <span class="hljs-keyword">return</span> config
&#125;,<span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">if</span> (error.<span class="hljs-property">response</span>.<span class="hljs-property">status</span>) &#123;
    <span class="hljs-comment">// 状态码超过 2xx 范围时都会调用该函数，处理错误响应</span>
    <span class="hljs-keyword">switch</span> (error.<span class="hljs-property">response</span>.<span class="hljs-property">status</span>) &#123;
      <span class="hljs-keyword">case</span> <span class="hljs-number">404</span>:
        <span class="hljs-title class_">ElMessage</span>(&#123;
          <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;error&#x27;</span>,
          <span class="hljs-attr">message</span>: <span class="hljs-string">&#x27;请求路径找不到！&#x27;</span>,
          <span class="hljs-attr">showClose</span>: <span class="hljs-literal">true</span>
        &#125;);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-number">502</span>:
        <span class="hljs-title class_">ElMessage</span>(&#123;
          <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;error&#x27;</span>,
          <span class="hljs-attr">message</span>: <span class="hljs-string">&#x27;服务器内部报错！&#x27;</span>,
          <span class="hljs-attr">showClose</span>: <span class="hljs-literal">true</span>
        &#125;);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-attr">default</span>:
        <span class="hljs-keyword">break</span>;
    &#125;
  &#125;
  <span class="hljs-keyword">return</span> error
&#125;)

<span class="hljs-keyword">const</span> request = &lt;T&gt;<span class="hljs-function">(<span class="hljs-params">url: <span class="hljs-built_in">string</span>, options?: &#123; [key: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span> &#125;</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>&lt;T&gt;(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> &#123;
    <span class="hljs-keyword">const</span> option = &#123;
      url,
      ...options,
      <span class="hljs-attr">baseURL</span>: <span class="hljs-string">&quot;/api&quot;</span>,
    &#125;
    <span class="hljs-title function_">axios</span>(option).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res: AxiosResponse&lt;T &amp; &#123; success: <span class="hljs-built_in">boolean</span>, data: <span class="hljs-built_in">any</span>, msg?: <span class="hljs-built_in">string</span>, token?: <span class="hljs-built_in">string</span>,  &#125;&gt;</span>) =&gt;</span> &#123;
      <span class="hljs-keyword">const</span> &#123; success, msg, &#125; = res.<span class="hljs-property">data</span>
      <span class="hljs-keyword">if</span> (success) &#123;
        <span class="hljs-title function_">resolve</span>(res.<span class="hljs-property">data</span>)
      &#125; <span class="hljs-keyword">else</span> &#123;
        <span class="hljs-title class_">ElMessage</span>.<span class="hljs-title function_">error</span>(&lt;<span class="hljs-built_in">string</span>&gt;msg)
        <span class="hljs-title function_">reject</span>(res.<span class="hljs-property">data</span>)
      &#125;
    &#125;).<span class="hljs-title function_">catch</span>(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> &#123;
      <span class="hljs-title function_">reject</span>(error)
    &#125;)
  &#125;)
&#125;

exprot &#123; request &#125;</code></pre></div>

<p>编写完成后，这个 axios 就已经完成了简单的二次封装。封装后就开始引入使用了，我这里是把所有的请求放到了一个 js 文件里面，在 <strong>src</strong> 目录创建一个 <strong>api</strong> 目录，再创建一个 index.js 文件，</p>
<div class="code-wrapper"><pre><code class="hljs typescript"><span class="hljs-comment">// 把封装好的 axios 引入</span>
<span class="hljs-keyword">import</span> &#123; request &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@/utils/http&#x27;</span>;

<span class="hljs-keyword">type</span> <span class="hljs-variable constant_">IDP</span>.<span class="hljs-property">LoginInParam</span> = &#123;
    password?: <span class="hljs-built_in">string</span> | <span class="hljs-literal">undefined</span>;
    username?: <span class="hljs-built_in">string</span> | <span class="hljs-literal">undefined</span>;
&#125;

<span class="hljs-keyword">type</span> <span class="hljs-variable constant_">IDP</span>.<span class="hljs-property">LoginInResponse</span> = &#123;
    <span class="hljs-attr">code</span>: <span class="hljs-built_in">number</span>;
    <span class="hljs-attr">data</span>: <span class="hljs-title class_">UserInfo</span>;
    <span class="hljs-attr">msg</span>: <span class="hljs-built_in">string</span>;
    <span class="hljs-attr">success</span>: <span class="hljs-built_in">boolean</span>;
&#125;

<span class="hljs-comment">/** 登录 POST /login */</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">idpLogin</span>(<span class="hljs-params">body: IDP.LoginInParam, options?: &#123; [key: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span> &#125;</span>) &#123;
  <span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">IDP</span>.<span class="hljs-property">LoginInResponse</span>&gt;(<span class="hljs-string">`/idp/login`</span>, &#123;
    <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,
    <span class="hljs-attr">headers</span>: &#123;
      <span class="hljs-string">&#x27;Content-Type&#x27;</span>: <span class="hljs-string">&#x27;application/json&#x27;</span>,
    &#125;,
    <span class="hljs-attr">data</span>: body,
    ...(options || &#123;&#125;),
  &#125;);
&#125;</code></pre></div>

<p>我看网上那些都是进行全局引入，我觉得那样不好，后面能按需导入就按需导入，这样能提高性能，毕竟总有几个页面不需要使用axios的。</p>
<div class="code-wrapper"><pre><code class="hljs vue">// 调用
&lt;template&gt;
	...
&lt;/template&gt;
&lt;script lang=&quot;ts&quot; setup&gt;
  import &#123; idpLogin &#125; from &quot;@/api/index&quot;
  import &#123; ElMessage &#125; from &quot;element-plus&quot;;
  
  const loading = ref&lt;boolean&gt;(false)
  const username = ref&lt;string&gt;(&quot;&quot;)
  const password = ref&lt;string&gt;(&quot;&quot;)
  
  const login = async () =&gt; &#123;
    loading.value = true
    try &#123;
      const &#123; data, success, msg &#125; = await idpLogin(&#123;
        username: username.value,
        password: password.value
      &#125;)
      if(success)&#123;
        ElMessage.success(&lt;string&gt;msg)
      &#125;
    &#125; catch (error) &#123;
      console.log(error)
    &#125; finally &#123;
      loading.value = false
    &#125;
  &#125;
&lt;/script&gt;</code></pre></div>


                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/blog/categories/javascript/" class="category-chain-item">javascript</a>
  
  
    <span>></span>
    
  <a href="/blog/categories/javascript/typescript/" class="category-chain-item">typescript</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/blog/tags/axios/">#axios</a>
      
    </div>
  
</div>


              

              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/blog/flex-layout.html" title="flex布局教程">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">flex布局教程</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/blog/seo-optimize.html" title="SEO 优化、前端优化">
                        <span class="hidden-mobile">SEO 优化、前端优化</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <span>枫🍁川</span> <i class="iconfont icon-love"></i> <span>前端小白</span> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>
<script type="text/javascript" src="/blog/js/click-love.js"></script>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/events.js" ></script>
<script  src="/blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/blog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/blog/live2dw/assets/chitose.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body>
</html>
